﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.NetworkInformation;

namespace ServerApplicationInstallationForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            Ping ping = new Ping();
            bool pinged = false;

            if(!boxServerName.Text.Equals(String.Empty)) 
            { 
                PingReply reply = ping.Send(boxServerName.Text.ToString());

                if (reply.Status == IPStatus.Success)
                {
                    pinged = true;
                }
            }
            if(pinged)
            {
                string[] lines = { boxServerName.Text.ToString(), boxInstallIIS.Checked.ToString(), boxInstallSQL.Checked.ToString(), boxInstallNET35.Checked.ToString(),
                                   boxInstallNET40.Checked.ToString(), boxInstallOracle.Checked.ToString(), boxInstallJBoss.Checked.ToString() };

                System.IO.File.WriteAllLines(@"\\genmills.com\mst\Unattend\Automated VM Build\Server-Application Installation\" + boxServerName.Text.ToString(), lines);
                MessageBox.Show("Created Request for " + boxServerName.Text.ToString());
            }
            else
            {
                MessageBox.Show("Server " + boxServerName.Text.ToString() + " Failed to ping.\n" + 
                                "Please ensure that it is online before using this utility");
            }
        }
    }
}
